import Mock from 'mockjs'
import apiUrl from '@/apis/urls/base'

const login = {
    url: apiUrl.Login,
    response: function (req) {
        const username = ['admin', 'super']
        //密码为: admin
        // const password = '21232f297a57a5a743894a0e4a801fc3';
        if (!username.includes(req.username)) {
            return {
                code: 500,
                message: '账户或密码错误',
                data: { isLogin: false },
            }
        }
        return {
            id: Mock.mock('@guid'),
            name: Mock.mock('@name'),
            username: req.username,
            avatar: 'https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif',
            token: Mock.mock('@guid'),
            introduction: 'I am a super administrator',
        };
    }
}

const logout = {
    type: 'get',
    url: apiUrl.Logout,
    response: true,
}

const NameList = []
const count = 100
for (let i = 0; i < count; i++) {
    NameList.push(Mock.mock({ name: '@first' }))
}
NameList.push({ name: 'mock-Pan' })

const searchUser = {
    type: 'get',
    url: apiUrl.searchUser,
    response: function (req) {
        const { name } = req.query
        const mockNameList = NameList.filter(item => {
            const lowerCaseName = item.name.toLowerCase()
            return !(name && lowerCaseName.indexOf(name.toLowerCase()) < 0)
        })
        return { items: mockNameList }
    },
}

const transactionList = {
    type: 'get',
    url: apiUrl.transactionList,
    response: function (req) {
        return {
            total: 20,
            'items|20': [{
                order_no: '@guid()',
                timestamp: +Mock.Random.date('T'),
                username: '@name()',
                price: '@float(1000, 15000, 0, 2)',
                'status|1': ['success', 'pending']
            }]
        }
    },
}




export default [
    login,
    logout,
    searchUser,
    transactionList,

]